<?php


namespace app\index\controller;


use think\Controller;

class Project extends Base
{
    public function index(){
        $project = model('project')->select();
        $Recommend = model('project')->order('create_time','desc')->limit(4)->select();
        $this->assign(compact('project','Recommend'));
        return view();
    }
    public function detail(){
        if(request()->isPost()){
            if(!session('vol_user.id')){
                $this->error('您需要先登录才能报名哦！');
            }
            $id = input('post.id');
            $data = [
              'project_id' => $id,
                'user_id' => session('vol_user.id')
            ];
           $find =  model('apply')->where($data)->find();
           if($find){
               $this->error('您已经申请过该项目，请勿重复申请');
           }
           $result =  model('apply')->save($data);
           if($result){
               $this->success('申请成功');
           }else{
               $this->error('申请失败');
           }

        }
        $project = model('project')->find(input('id'));
        $this->assign(compact('project'));
        return view();
    }
}
